package com.gzk.oeno.ihm;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JPanel;

import com.gzk.oeno.ihm.cave.CaveSelectionPanel;
import com.gzk.oeno.ihm.vin.AllVinIFrame;
import com.gzk.oeno.tech.ui.IdInternalFrame;
import com.gzk.utils.ihm.UIUtils;
import com.gzk.utils.ihm.panes.TitledPane;

public class HomeIFrame extends IdInternalFrame implements ActionListener{

	
	private JButton vinsListButton;
	
	public HomeIFrame(){
		super("Accueil", false, false, true, true);
		setFrameIcon(UIUtils.loadSilentIcon("icons/home_16.png"));
		setContentPane(buildPanel());
	}
	
	
	
	private JPanel buildPanel(){
		JPanel pane = new JPanel(new GridLayout(1, 2));
		
		JPanel cavePanel =  new CaveSelectionPanel();
		cavePanel.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1, Color.black));
		
		JPanel vinPanel = new JPanel(new FlowLayout());
		vinPanel.add(getVinsListButton());
		
		pane.add(new TitledPane("Caves", cavePanel));
		pane.add(new TitledPane("Catalogue des vins", vinPanel));
		
		return pane;
	}


	
	protected JButton getVinsListButton(){
		if (vinsListButton == null){
			vinsListButton = new JButton("Catalogue des vins", UIUtils.loadSilentIcon("icons/oenothek_64.png"));
			vinsListButton.setFocusPainted(false);
			vinsListButton.addActionListener(this);
		}
		return vinsListButton;
	}

	@Override
	public void actionPerformed(ActionEvent ev) {
		if (ev.getSource().equals(getVinsListButton())){
			MainOenoFrame.INSTANCE.addIFrame(new AllVinIFrame(), true);
		}
	}


	@Override
	public String getId() {
		return getTitle();
	}
	
	
}
